<?php
/**
 * 《货运需求》实现类
 *
 * @author 孙晓晔
 * @version $Id: Work.class.php 1035 2010-03-26 05:24:59Z sunxy $
 */

require_once(dirname(__FILE__) . '/../express/Requirement.class.php');

class RequirementCustomer extends Requirement {
	
	public $orderby = array(
		'-' => '请选择',
		'type' => '类型',
		'way' => '方式',

		'1' => '创建时间',
		'2' => '更新时间',
	);
	
	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct($request);
	}

	function pretreat($controller) {
		parent::pretreat($controller);
	}

	function find($controller, $request) {
		$this->pretreat($controller);

		$controller->assign('t1', date("Y-m-01"));

		$controller->display($request, 'express/requirement/customer/find');
		return true;
	}
	
	function _my() {
		$emp = $_SESSION['id'];
		
		return sprintf(" visible = 1 AND (emp = '%s' OR oper = '%s')", $emp, $emp);
	}
	
	function findPost($controller, $request) {
		$this->pretreat($controller);

		$this->findPara($controller, $request);

		$db = newdb($this->dsn_r);
		$fmt = "SELECT * FROM %s a %s %s";
		$where = $this->_where($request);
		$orderby = $this->_orderby();		
		$sql = sprintf($fmt, $this->tbl, $where, $orderby);
		debug($sql);

		$pager_option = array (
            'db' => $db,
            'sql' => $sql,
            'PageSize' => $this->pagesize,
            'CurrentPageID' => $request['p'],
            'numItems' => $request['n']
		);

		$pager = @new Pager($pager_option);
		$data = $pager->getPageData();

		if ($pager->number > 0) {

			$count = 0;
			$from = $pager->from;
			while ($count < $pager->number) {
				$row = $data[$count];
				$row = $this->_view(null, $row);
				
				$row['p'] = $this->_plan($row['plan']);
				
				$row = $this->_orderby_x($controller, $row, $this->orderby_s);

				$row['is_delete'] = $this->_is_delete($row);

				$data[$count] = $row;
				$count++;
			}
			$controller->assign_by_ref('result', $data);
			$controller->assign_by_ref('pager', $pager);
		}

		$controller->display($request, 'express/requirement/customer/list');
		return true;
	}
	
	function add($controller, $request) {
		$this->pretreat($controller);
	
		$controller->assign('t1', strtotime('1 day'));
	
		$controller->display($request, 'express/requirement/customer/add');
		return true;
	}
	
	function edit($controller, $request) {
		$this->pretreat($controller);
	
		$id = $request['id'];
		$row = $this->_view($id);
	
		$controller->assign_by_ref('result', $row);
	
		$controller->display($request, 'express/requirement/customer/edit');
		return true;
	}
	
	function copy($controller, $request) {
		$this->pretreat($controller);
	
		$id = $request['id'];
		$row = $this->_view($id);
	
		$controller->assign_by_ref('result', $row);
	
		$controller->display($request, 'express/requirement/customer/copy');
		return true;
	}
}
?>